/*
* Copyright (C) 2012 Manuel Pérez
*
* This file is part of OpenSudoku.
*
* OpenSudoku is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSudoku is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSudoku. If not, see <http://www.gnu.org/licenses/>.
*
*/
package dBasea;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Balorazioak {

	public List<String> listatuEremuak() throws SQLException {
		DatuBasea dbk = DatuBasea.getInstance();
		String query = "SELECT deskripzioa FROM Eremu";
		ResultSet rs = dbk.executeSQL(query);
		List<String> lista = new ArrayList<String>();
		while (rs.next()) {
			lista.add(rs.getString("deskripzioa"));
		}
		rs.close();

		return lista;
	}

	public int lortuUrtea() throws SQLException {
		DatuBasea dbk = DatuBasea.getInstance();
		String query = "SELECT max(idIstripua) FROM Istripua";
		ResultSet rs = dbk.executeSQL(query);
		int istri = -1;
		if (rs.next()) {
			istri = rs.getInt(1);
		}
		rs.close();
		return istri;
	}

	public void balorazioaSortu(String eremua, String matrikula, int Istripua,
			String behaketak, float balorea) throws SQLException {
		DatuBasea dbk = DatuBasea.getInstance();
		String query = "INSERT INTO BalorazioKotxeIstripu (idEremu,matrikula,idIstripua,behaketak,balorea)"
				+ " VALUES ((Select idEremu from Eremu where deskripzioa='"
				+ eremua
				+ "'),'"
				+ matrikula
				+ "' , "
				+ Istripua
				+ " , '"
				+ behaketak + "'," + balorea + ")";
		dbk.executeSQL(query);

	}

}
